<?php
function prevent_param($val) {
    return trim(addslashes(strip_tags($val)));
}

function format_number($val) {
    $val = trim($val);
    $svals = explode(".", $val); 
    $sval = $svals[0]; 
    $n = 0;
    $result = "";
    for ($i = strlen($sval) - 1; $i >= 0; $i--) {
        if ($sval[$i] == ".") {
            $n = -1;
        } else if ($n == 3) {
            $result = ",$result"; //??? comma
            $n = 0;
        }
        $n++;
        $result = $sval[$i] . $result;
    }
    if (strlen($svals[1]) == 0) { $svals[1] = "00";}
    else if (strlen($svals[1]) == 1) { $svals[1] = $svals[1] . "0";}
    else if (strlen($svals[1]) == 2) {  $svals[1] = $svals[1];}
    return ( count($svals) > 1 ) ? $result . '.' . $svals[1] : $result;
}